package com.woniu.controller;


import com.woniu.commons.Result;
import com.woniu.controller.component.ControllerBase;
import com.woniu.model.EUser;
import com.woniu.model.Page;
import com.woniu.service.IEUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Kevin Kwok
 * @since 2021-04-13
 */
@RestController
@RequestMapping("/customer")
@Slf4j
public class EUserController extends ControllerBase {

    @Resource
    private IEUserService userService;

    @GetMapping("/queryAll")
    @RequiresPermissions({"账号管理"})
    public Result queryAllCustomer(Page page){
        log.info("分页参数：{}", page);
        //获取当前页的信息
        List<EUser> currentPageUser = userService.getCurrentPageUser(page.getPageIndex(), page.getPageSize());
        //获得分页的数据
        Page pageInfo = userService.getPageInfo(page.getPageIndex(), page.getPageSize());

        return new Result("200", "success", pageInfo, currentPageUser);
    }

    @RequiresPermissions({"账号管理"})
    @GetMapping("/frozen/{id}")
    public Result frozenAccount(@PathVariable("id") Integer id){
        int i = userService.frozenAccount(id);
        if(i==0){
            return new Result("400", "销户失败", null, null);
        }
        return new Result("200", "销户成功", null, null);
    }

    @RequiresPermissions({"账号管理"})
    @GetMapping("/edit")
    public Result editAccount(Integer id,String idNunber,Integer status){
        log.info("分页参数：{}", idNunber);
        int i = userService.editAccount(id, idNunber, status);
        if(i==0){
            return new Result("400", "编辑失败", null, null);
        }
        return new Result("200", "编辑成功", null, null);
    }
}

